package com.emma.controller;

import com.emma.entity.Address;
import com.emma.entity.PageBean;
import com.emma.entity.ResultInfo;
import com.emma.service.AddressService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping("/address")
public class AddressController {

    @Autowired
    private AddressService addressService;

    //1.分页

    @RequestMapping("/find")
    public ResultInfo find(@RequestBody Map<String, Object> paramMap){
        PageBean<Address> pageBean = addressService.find(paramMap);
        System.out.println("data:"+pageBean);
        return new ResultInfo(true,pageBean);
    }

    @RequestMapping("/add")
    public ResultInfo add(@RequestBody Address address){
        System.out.println("进行了添加前");
         addressService.add(address);
        System.out.println("进行了添加");
        return new ResultInfo(true,"添加成功呀");
    }
    @RequestMapping("/update")
    public ResultInfo update(@RequestBody Address address){
        addressService.update(address);
        return new ResultInfo(true,"修改成功呀");
    }
    @RequestMapping("/delete")
    public ResultInfo update(Integer aid){
        addressService.delete(aid);
        return new ResultInfo(true,"删除成功呀");
    }

    @RequestMapping("/changeDefaultAddress")
    public ResultInfo changeDefaultAddress(Integer aid){
        addressService.changeDefault(aid);
        return new ResultInfo(true,"修改默认地址成功呀");
    }
}
